﻿using EPE.BLL;
using EPE.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace EPE.WPF
{
    /// <summary>
    /// ShopsProjectConditionForm.xaml 的交互逻辑
    /// </summary>
    public partial class ShopsProjectConditionForm : Window
    {
        public ShopsProjectConditionForm()
        {
            InitializeComponent();
        }

        private CShopsProject _model = new CShopsProject();

        public CShopsProject Model
        {
            get { return _model; }
            set { _model = value; }
        }

        CLoginUser userinfo = new CLoginUser();
        public ShopsProjectConditionForm(CLoginUser pargUserinfo)
        {
            InitializeComponent();
            userinfo = pargUserinfo;
            BindData();
            
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            BindData();
        }

        /// <summary>
        /// 
        /// </summary>
        private void BindData()
        {
            DataSet ds = new DataSet();



            ShopsProject bll = new ShopsProject();


            ds = bll.GetListByPage(this.txtProjectName.Text, userinfo.CompanyId.ToString(), "projectname", this.pagectrl.PageIndex, this.pagectrl.PageSize);

            DataTable dt = ds.Tables[0];

            this.dgList.DataContext = dt;
            this.pagectrl.TotalCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
        }

        private void dgList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var drv = (DataRowView)this.dgList.SelectedItem;
            _model.projectid = Convert.ToInt32(drv["projectid"]);
            _model.projectname = drv["projectname"].ToString();
           
            this.Close();
        }

        private void pagectrl_PagerIndexChanged(object sender, EventArgs e)
        {
            BindData();
        }

    }
}
